import React, {useCallback, useEffect, useState} from 'react';
import Child from "./components/Child";

function App(props) {
    const [num, setNum] = useState(0);
    const [userName, setUserName] = useState("zhangsan");
    // 缓存函数：第一次加载时会进行缓存。
    const changeUserName = useCallback(function (s) {
        setUserName(userName + s)
    }, [num]);
    return (
        <div>
            <button onClick={() => setNum(num + 1)}>{num}</button>
            <button onClick={() => changeUserName("|")}>{userName}</button>
            <hr/>
            <Child changeUserName={changeUserName} userName={userName}/>
        </div>
    );
}

export default App;